package org.bwapi.bridge.model;

import java.util.Set;

import org.apache.commons.collections15.Transformer;
import org.bwapi.bridge.swig.RegionSet;
import org.bwapi.bridge.swig.RegionSetIterator;
import org.bwapi.bridge.swig.RegionSpacelessSet;
import org.bwapi.bridge.swig.RegionSpacelessSetIterator;
import org.bwapi.bridge.swig.SWIGTYPE_p_Region;
import org.bwapi.bridge.swig.SWIGTYPE_p_std__setT_BWTA__Region_p_t;
import org.bwapi.bridge.swig.SWIGTYPE_p_std__setT_Region_p_t;
import org.cretz.swig.collection.NativeSet;
import org.cretz.swig.util.SwigUtils;

/**
 * Region
 * 
 * @see <a href="http://code.google.com/p/bwta/wiki/Region">Region</a>
 * 
 * @author Chad Retz
 * 
 * @since 0.2
 */
public class Region {
	private static final Transformer<Region, org.bwapi.bridge.swig.Region> FROM = 
		new Transformer<Region, org.bwapi.bridge.swig.Region>() {
			@Override
			public org.bwapi.bridge.swig.Region transform(Region region) {
				return region.getRegion();
			}
		};
		
	private static final Transformer<org.bwapi.bridge.swig.Region, Region> TO = 
		new Transformer<org.bwapi.bridge.swig.Region, Region>() {
			@Override
			public Region transform(org.bwapi.bridge.swig.Region region) {
				return new Region(region);
			}
		};
		
	private static final Transformer<Region, SWIGTYPE_p_Region> FROM_SPACELESS = 
		new Transformer<Region, SWIGTYPE_p_Region>() {
			@Override
			public SWIGTYPE_p_Region transform(Region region) {
				return region.getPointer();
			}
		};
		
	private static final Transformer<SWIGTYPE_p_Region, Region> TO_SPACELESS = 
		new Transformer<SWIGTYPE_p_Region, Region>() {
			@Override
			public Region transform(SWIGTYPE_p_Region region) {
				return new Region(region);
			}
		};
		
	static Set<Region> newSet(SWIGTYPE_p_std__setT_BWTA__Region_p_t nativeSet) {
		return new NativeSet<Region, org.bwapi.bridge.swig.Region>(
				org.bwapi.bridge.swig.Region.class, RegionSetIterator.class, 
				nativeSet, RegionSet.class, FROM, TO);
	}
		
	static Set<Region> newSet(SWIGTYPE_p_std__setT_Region_p_t nativeSet) {
		return new NativeSet<Region, SWIGTYPE_p_Region>(
				SWIGTYPE_p_Region.class, RegionSpacelessSetIterator.class, 
				nativeSet, RegionSpacelessSet.class, FROM_SPACELESS, TO_SPACELESS);
	}

	private final org.bwapi.bridge.swig.Region region;

	Region(org.bwapi.bridge.swig.Region region) {
		this.region = region;
	}
	
	Region(SWIGTYPE_p_Region region) {
		this(SwigUtils.getSwigPointer(SwigUtils.getSwigPointer(region), 
				false, org.bwapi.bridge.swig.Region.class));
	}
	
	org.bwapi.bridge.swig.Region getRegion() {
		return region;
	}
	
	SWIGTYPE_p_Region getPointer() {
		return SwigUtils.getSwigPointer(region, SWIGTYPE_p_Region.class);
	}

	public Polygon getPolygon() {
		return new Polygon(region.getPolygon());
	}

	public Position getCenter() {
		return new Position(region.getCenter());
	}

	public Set<Chokepoint> getChokepoints() {
		return Chokepoint.newSet(region.getChokepoints());
	}

	public Set<BaseLocation> getBaseLocations() {
		return BaseLocation.newSet(region.getBaseLocations());
	}
}
